package databases

import (
	"Godzilla/common/ini"
	"log"
)

var tcpMap = make(map[string]string)//tcp服务端
var tcpArr []string //服务端组

func GetTcpConfig(str string) string {

	return tcpMap[str]
}

func SetTcpConfig(key string, value string) bool {
	tcpMap[key] = value
	if _, err := tcpMap[key]; err == false {
		return false
	}
	return true
}

func TcpSetConfig() bool {
	var (
		Host 	string
		Port	string
	)

	driver := "tcpServer"

	cfg, err := ini.NewIni()
	if err != nil {
		log.Println(err)
		return false
	}

	Host = cfg.Section(driver).Key("Host").String()
	Port = cfg.Section(driver).Key("Port").String()

	SetTcpConfig("Host",Host)
	SetTcpConfig("Port", Port)

	return true
}

func TcpArrSetConfig() bool {
	cfg, err := ini.NewIniShadowLoad()
	if err != nil {
		log.Println(err)
		return false
	}
	tcpArr = cfg.Section("tcpServerArr").Key("dsn").ValueWithShadows()
	return true
}

func GetTcpArrConfig() []string {
	return tcpArr
}